package reflect;

import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;

/**
 * 反射机制访问方法上的注解
 */
public class ReflectDemo12 {
    public static void main(String[] args) throws Exception {
        //判断Person类上的sayHello方法是否被注解@AutoRunMethod标注
        Class cls = Class.forName("reflect.Person");

        Method[] methods = cls.getDeclaredMethods();
        for(Method method : methods) {
            //获取Person上的sayHello方法
//            Method method = cls.getDeclaredMethod("sayHello");
//        Method method = cls.getDeclaredMethod("sleep");
            boolean mark = method.isAnnotationPresent(AutoRunMethod.class);
            if (mark) {
                System.out.println(method.getName()+"()被标注了");
            } else {
                System.out.println(method.getName()+"()没有被标注");
            }
        }
    }
}
